package com.tgy.algorithm.base;


class LimitQueue {
    private int limit;
    private int size;
    private int putIndex;
    private int getIndex;
    private int[] container;

    public LimitQueue(int[] container) {
        this.container = container;
        this.limit = container.length;
        this.size = 0;
        this.putIndex = 0;
        this.getIndex = 0;
    }

    public boolean isEmpty() {
        return this.size == 0;
    }

    public int size() {
        return this.size;
    }

    public void put(int value) {
        if (size >= limit) {
            throw new ArrayIndexOutOfBoundsException("超出了指定容量大小");
        }
        this.container[putIndex] = value;
        this.addPutIndex();
        this.size++;
    }


    public int get(int index) {
        if (this.isEmpty()) {
            throw new ArrayIndexOutOfBoundsException("容量里面没有内容");
        }

        int val = this.container[this.getIndex];
        this.addGetIndex();
        this.size--;
        return val;
    }

    private void addPutIndex() {
        this.putIndex++;
        if (putIndex >= limit) {
            putIndex = 0;
        }
    }

    private void addGetIndex() {
        this.getIndex++;
        if (getIndex >= limit) {
            getIndex = 0;
        }
    }

}

public class _容量特定的队列 {



    public static void main(String[] args) {
       LimitQueue queue = new LimitQueue(new int[]{1,2,3});
    }
}
